Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dcomprasion StructsDiff was implemented #723

Merged
merged 1 commit into from
Feb 26, 2024
Merged

Conversation

worryg0d
Copy link
Collaborator

@worryg0d worryg0d commented Feb 23, 2024

The PR provides the dcomparison.StructsDiff func which deeply compares two struct and returns dcomparison.ObjectDiffs with differences between both of them.

The path to each field is based on:

  1. json field name if there is a json tag with json field name
  2. the name of the field directly if there is no json field name
  3. if there is a json inline constraint ,inline for an embedded struct it skips its name

The package also provides dcomparisonSkip struct tag which indicates if the struct field should be included in comparasing.

type SomeStruct struct {
       // Field will be included in the result with json field name `field`
	Field string `json:"field"`
        // FieldToBeSkipped will not be included in comparasing
        FieldToBeSkipped `json"fieldToBeSkipped" dcomprasionSkip"true"`
        // unexportedField will not be included too 
        unexportedField `json"unexportedField"`
       // In this case the name FieldWithJSONSkipConstraint will be included in the result 
        FieldWithJSONSkipConstraint `json"-"`
}

type StructWithEmbedded struct {
        // the name of the ExportedStruct will not be included in the result.
        // It means that the resulting path to the field inside 
        // embedded struct will be `StructWithEmbedded.field`
	ExportedStruct `json:",inline"`
}

@worryg0d worryg0d added the enhancement New feature or request label Feb 23, 2024
@worryg0d worryg0d self-assigned this Feb 23, 2024
@worryg0d worryg0d marked this pull request as draft February 23, 2024 11:08
@worryg0d worryg0d marked this pull request as ready for review February 23, 2024 14:44
@worryg0d worryg0d changed the title dcomprasion StructDiff was implemnted dcomprasion StructsDiff was implemented Feb 23, 2024
@worryg0d worryg0d force-pushed the dcomprasion-struct-diff branch 2 times, most recently from 7e7afd5 to 3f900b3 Compare February 23, 2024 14:51
@ribaraka ribaraka merged commit 13f37bd into main Feb 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants